﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPlatformPages.h"
#include "GmGbmpUiConfigurationCommandRegister.h"
#include "GbmpUiPlatformCommandIds.h"
#include "IPublishConfig.h"
#include "GcmpCommandNames.h"
#include "IApplication.h"
#include "IMainWindow.h"
#include "IStatusBar.h"
#include "GbmpControlIds.h"
#include "ICommandButtonDefinition.h"
#include "ILabelDefinition.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace gcmp;

void AddPlatformPages::AddStatusBar()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(IMainWindow::GetMainWindow(), L"IMainWindow::GetMainWindow()为空",L"GDMPLab",L"2024-03-30");

    IStatusBar* pStatusBar = IMainWindow::GetMainWindow()->GetStatusBar();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pStatusBar, L"pStatusBar为空",L"GDMPLab",L"2024-03-30");

    {
        int minWidth = 600;
        OwnerPtr<ILabelDefinition> pLabel = ILabelDefinition::Create(ID_STATUS_BAR_PROMPT_LABEL, L"", GBMP_TR(L"即时信息"));
        OwnerPtr<IStatusBarPanel> pPanel = IStatusBarPanel::Create(ID_STATUS_BAR_PROMPT_PANEL, minWidth);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pPanel, L"pPanel为空",L"GDMPLab",L"2024-03-30");

        pPanel->AddLabel(TransferOwnership(pLabel));
        pStatusBar->AppendPanel(TransferOwnership(pPanel), StatusBarAlignment::Left);
    }
    {
        int minWidth = 150;
        OwnerPtr<ILabelDefinition> pLabel = ILabelDefinition::Create(ID_STATUS_BAR_KEYBOARD_LABEL, L"", GBMP_TR(L"快捷键信息"));
        OwnerPtr<IStatusBarPanel> pPanel = IStatusBarPanel::Create(ID_STATUS_BAR_KEYBOARD_PANEL, minWidth);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pPanel, L"pPanel为空",L"GDMPLab",L"2024-03-30");

        pPanel->AddLabel(TransferOwnership(pLabel));
        pStatusBar->AppendPanel(TransferOwnership(pPanel), StatusBarAlignment::Left);
    }
    const IConfigRecord* pInHouseModeConfigRecord = IPublishConfig::GetConfigRecord(PublishConfigRecordNames::InHouseMode);
    if (pInHouseModeConfigRecord && pInHouseModeConfigRecord->IsInternalIdentifyCodeValue())
    {
        OwnerPtr<IStatusBarPanel> opPanel = IStatusBarPanel::Create(STATUSBAR_FILTER_PANEL);
        DBG_WARN_AND_RETURN_VOID_UNLESS(opPanel, L"pPanel为空",L"GDMPLab",L"2024-03-30");
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_LOCATOR_UPDATE_DISPLAY_STATUS, GBMP_TR(L"显示罗盘"), GBMP_TR(L"显示罗盘"), ID_CMD_LOCATOR_UPDATE_DISPLAY_STATUS, L"", ButtonStyle::TextOnly);
            opPanel->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_PICK_FILTER_GBMP, GBMP_TR(L"拾取过滤"), GBMP_TR(L"拾取过滤"), ID_CMD_PICK_FILTER_GBMP, L":images/statusbar/状态栏_拾取过滤.png", ButtonStyle::TextBesideIcon);
            opPanel->AddButton(TransferOwnership(opButtonDef));
        }        
        pStatusBar->AppendPanel(TransferOwnership(opPanel), StatusBarAlignment::Right);
    }
}

